package cn.tedu.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

//
public class Test4 {
    public static void main(String[] args) throws Exception {
        Connection conn = null;
        PreparedStatement ps = null;
        try {
            conn = JDBCUtils.getconnection();
//        Class.forName("com.mysql.jdbc.Driver");
//        String u  rl="jdbc:mysql:///abc?characterEncoding=utf8";
//        Connection conn= DriverManager.getConnection(url,"root","root105");
            //高级工具类
            String sql = "delete from user_1 where id=?";
            ps = conn.prepareStatement(sql);
            ps.setInt(1, 1);//第一个？设置值为1
            int rows = ps.executeUpdate();
            System.out.println("删除成功");
        } catch (Exception e) {
            System.out.println("执行失败");
        } finally {
            JDBCUtils.close(null, ps, conn);

//            if(ps!=null){
//               try{
//                  ps.close();
//
//               } catch (SQLException throwables){
//                   throwables.printStackTrace();
//               }
//            }
//            if(conn!=null) {
//                try {
//                    conn.close();
//
//                } catch (SQLException throwables) {
//                    throwables.printStackTrace();
//                }
//            }
        }
    }
}
